
describe('App.AccountTransaction', function() {

    var transaction,
        effectiveDate = "2013-03-15",
        postDate ="2013-02-14";
    it('transferDate', function() {
        transaction = App.AccountTransaction.create({
            "forAccount": App.HaveAccount.create(),
            "effectiveDate":effectiveDate,
            "postDate" :postDate
        });
        expect(transaction.get('transferDate')).toEqual(postDate);
    });
    it('transferDate forAccount as credit card', function() {
        transaction = App.AccountTransaction.create({
            "forAccount": App.CardAccount.create(),
            "effectiveDate":effectiveDate,
            "postDate" :postDate
        });
        expect(transaction.get('transferDate')).toEqual(effectiveDate);
    });
});

describe('App.PaymentTransaction', function() {

    it('type with transactionTypeCode', function() {
        var transaction = App.PaymentTransaction.create({
            "transactionTypeCode" : "15`Transfer Between Own Accounts"
        });
        expect(transaction.get('type')).toEqual('15');
    });
    it('type with transactionTypeCode null', function() {
        var transaction = App.PaymentTransaction.create({
        });
        expect(transaction.get('type')).toEqual('');
    });

    it('displayableObjectInList', function() {

        var t_transaction = {
            key : "2011-10-12",
            transferDate: "2011-10-12T05:30:00.000+0530",
            currencyCode: "INR",
            amount: 2000,
            transactionType : "15`Transfer Between Own Accounts"
        };

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        var expectedOutput = {
            id:'2011-10-12',
            title: 'Transfer Between Own Accounts',
            secondLabel: 'aXcess Plus',
            amount: 2000,
            currencyCode:'INR',
            isNegative :false
        };

        spyOn(transaction, 'getFromAccountName').andReturn('aXcess Plus')
        expect(JSON.stringify(transaction.get('displayableObjectInList'))).toEqual(JSON.stringify(expectedOutput));
    });

    it('displayableObject', function() {

        var t_transaction = {
            "payee":{"drAccount":"","payeeId":3099,"payeeType":"2","payeeName":"IBFT_Khan_ACC","payeeStatus":"A","merchantId":""},
            "toAccountVO":{"accountDescription":"IBFT_Khan_ACC","accountNumber":"18521000507822","currencyCode":"INR"},
            "merchantVO":{},
            "transactionMode":"I",
            "channel":"IBKBMW",
            "currencyCode":"INR",
            "transactionTypeCode":"18`InterBank Fund Transfer",
            "reference":[null],
            "remark":"Transferring funds to a third party account in another bank",
            "amount":203,
            "transferDate":"2012-06-11T21:06:03.000+0530",
            "transactionStatus":{"transactionId":"00000000-0000-0000-1206-112002022200","transactionStatus":"2"},
            "fromAccount":{"accountDescription":"aXcess Plus","accountNumber":"22510132401","currencyCode":"INR"},
            "recurring":{"isRecurring":false},
            "merchantId":"",
            "merchant":{},
            "destinationAccountName":"IBFT_Khan_ACC",
            "createdDate":"2012-06-11T20:02:35.784+0530",
            "updatedBy":"9171981351",
            "updatedDate":"2012-06-11T20:02:35.784+0530"
        }

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        var expectedOutput = [
                    {"key": "Transaction type", "value": "InterBank Fund Transfer"},
                    {"key": "Status","value": "SUBMITTED"},
                    {"key": "Receipt number","value": "1206-112002022200"},
                    {"key": "Account to be paid from", "value": "aXcess Plus, 22510132401"},
                    {"key": "Account to be paid to","value": "IBFT_Khan_ACC, 18521000507822"},
                    {
                        "key": "Amount",
                        "value": {
                            "currencyCode": "INR",
                            "amount": 203
                        },
                        "isAmount": true
                    },
                    {"key": "When to be paid","value":"Monday, 11 June 2012"},
                    {"key":"Future payments scheduled","value":"No"},
                    {"key":"Description","value":"Transferring funds to a third party account in another bank"}
        ];
        spyOn( App.PaymentTransaction, 'isCashAdvance').andReturn(false);
        expect(JSON.stringify(transaction.get('displayableObject'))).toEqual(JSON.stringify(expectedOutput));
    });
    it('displayableObject with repeat ', function() {

        var t_transaction ={
            "payee":{"drAccount":"","payeeId":3099,"payeeType":"2","payeeName":"IBFT_Khan_ACC","payeeStatus":"A","merchantId":""},
            "toAccountVO":{"accountDescription":"IBFT_Khan_ACC","accountNumber":"18521000507822","currencyCode":"INR"},
            "merchantVO":{},
            "transactionMode":"S",
            "currencyCode":"INR",
            "transactionTypeCode":"18`InterBank Fund Transfer",
            "reference":[null],
            "remark":"Transferring funds to a third party account in another bank",
            "amount":203,
            "transferDate":"2012-06-02T05:10:28.000+0530",
            "transactionStatus":{"transactionId":"00000000-0000-0000-1206-112002022200","transactionStatus":"2"},
            "fromAccount":{"accountDescription":"aXcess Plus","accountNumber":"22510132401","currencyCode":"INR"},
            "recurring":{"frequency":"Monthly","endDate":"2012-07-02T00:00:00.000+0530","isRecurring":true},
            "merchantId":"",
            "merchant":{},
            "destinationAccountName":"IBFT_Khan_ACC",
            "createdDate":"2011-06-30T11:41:27.223+0530",
            "updatedBy":"SCHEDULER"
        }

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        var expectedOutput = [
            {"key": "Transaction type", "value": "InterBank Fund Transfer"},
            {"key": "Status","value": "SUBMITTED"},
            {"key": "Receipt number","value": "1206-112002022200"},
            {"key": "Account to be paid from", "value": "aXcess Plus, 22510132401"},
            {"key": "Account to be paid to","value": "IBFT_Khan_ACC, 18521000507822"},
            {
                "key": "Amount",
                "value": {
                    "currencyCode": "INR",
                    "amount": 203
                },
                "isAmount": true
            },
            {"key": "When to be paid","value":"Saturday, 02 June 2012"},
            {"key":"Future payments scheduled","value":"Monthly"},
            {"key":"End date","value":"Monday, 02 July 2012"},
            {"key":"Description","value":"Transferring funds to a third party account in another bank"}
        ];

        spyOn( App.PaymentTransaction, 'isCashAdvance').andReturn(false);
        expect(JSON.stringify(transaction.get('displayableObject'))).toEqual(JSON.stringify(expectedOutput));
    });

    it('displayableObject with cash advance not available', function() {

        var t_transaction ={
            "payee":{"drAccount":"","payeeId":3211,"payeeType":"1","payeeName":"bol","payeeStatus":"A","merchantId":""},
            "toAccountVO":{"accountDescription":"bol","accountNumber":"45678901237","currencyCode":"INR"},
            "merchantVO":{},
            "transactionMode":"S",
            "currencyCode":"INR",
            "transactionTypeCode":"23`",
            "reference":[null],
            "remark":"cash advance",
            "amount":203,
            "transferDate":"2012-06-02T05:10:28.000+0530",
            "transactionStatus":{"transactionId":"00000000-0000-0000-1206-112002022200","transactionStatus":"2"},
            "fromAccount":{"accountDescription":"Manhattan Platinum","accountNumber":"4129034830000573","currencyCode":"INR"},
            "recurring":{"frequency":"Monthly","endDate":"2012-07-02T00:00:00.000+0530","isRecurring":true},
            "merchantId":"",
            "merchant":{},
            "destinationAccountName":"bol",
            "createdDate":"2011-06-30T11:41:27.223+0530",
            "updatedBy":"SCHEDULER"
        }

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        var expectedOutput = [
            {"key": "Transaction type", "value": "3rd Party Transfer Cash Advance"},
            {"key": "Status","value": "SUBMITTED"},
            {"key": "Receipt number","value": "1206-112002022200"},
            {"key": "Account to be paid from", "value": "Manhattan Platinum, 4129034830000573"},
            {"key": "Available Cash Advance Limit","value": "Not Available"},
            {"key": "Bank charges","value": "Cash advance fee of 3% of the cash withdrawal amount, subject to a minimum of INR 300."},
            {"key": "Finance charges","value": "3.49% per month on the amount withdrawn."},
            {"key": "Account to be paid to","value": "bol, 45678901237"},
            {
                "key": "Amount",
                "value": {
                    "currencyCode": "INR",
                    "amount": 203
                },
                "isAmount": true
            },
            {"key": "When to be paid","value":"Saturday, 02 June 2012"},
            {"key":"Future payments scheduled","value":"Monthly"},
            {"key":"End date","value":"Monday, 02 July 2012"},
            {"key":"Description","value":"cash advance"}
        ];

        spyOn( App.PaymentTransaction, 'isCashAdvance').andReturn(true);
        expect(JSON.stringify(transaction.get('displayableObject'))).toEqual(JSON.stringify(expectedOutput));
    });

    it('displayableObject with cash advance not available', function() {

        var t_transaction ={
            "payee":{"drAccount":"","payeeId":3211,"payeeType":"1","payeeName":"bol","payeeStatus":"A","merchantId":""},
            "toAccountVO":{"accountDescription":"bol","accountNumber":"45678901237","currencyCode":"INR"},
            "merchantVO":{},
            "transactionMode":"S",
            "currencyCode":"INR",
            "cardAvailableLimit":11100.0000,
            "transactionTypeCode":"23`",
            "reference":[null],
            "remark":"cash advance",
            "amount":203,
            "transferDate":"2012-06-02T05:10:28.000+0530",
            "transactionStatus":{"transactionId":"00000000-0000-0000-1206-112002022200","transactionStatus":"2"},
            "fromAccount":{"accountDescription":"Manhattan Platinum","accountNumber":"4129034830000573","currencyCode":"INR"},
            "recurring":{"frequency":"Monthly","endDate":"2012-07-02T00:00:00.000+0530","isRecurring":true},
            "merchantId":"",
            "merchant":{},
            "destinationAccountName":"bol",
            "createdDate":"2011-06-30T11:41:27.223+0530",
            "updatedBy":"SCHEDULER"
        }

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        var expectedOutput = [
            {"key": "Transaction type", "value": "3rd Party Transfer Cash Advance"},
            {"key": "Status","value": "SUBMITTED"},
            {"key": "Receipt number","value": "1206-112002022200"},
            {"key": "Account to be paid from", "value": "Manhattan Platinum, 4129034830000573"},
            {
                "key": "Available Cash Advance Limit",
                "value": {
                    "currencyCode": "INR",
                    "amount": 11100
                },
                "isAmount": true,
                "withoutColorIndicator": true
            },
            {"key": "Bank charges","value": "Cash advance fee of 3% of the cash withdrawal amount, subject to a minimum of INR 300."},
            {"key": "Finance charges","value": "3.49% per month on the amount withdrawn."},
            {"key": "Account to be paid to","value": "bol, 45678901237"},
            {
                "key": "Amount",
                "value": {
                    "currencyCode": "INR",
                    "amount": 203
                },
                "isAmount": true
            },
            {"key": "When to be paid","value":"Saturday, 02 June 2012"},
            {"key":"Future payments scheduled","value":"Monthly"},
            {"key":"End date","value":"Monday, 02 July 2012"},
            {"key":"Description","value":"cash advance"}
        ];

        spyOn( App.PaymentTransaction, 'isCashAdvance').andReturn(true);
        expect(JSON.stringify(transaction.get('displayableObject'))).toEqual(JSON.stringify(expectedOutput));
    });

    it('typeDesc', function() {
        var t_transaction = {
            key : "2011-10-12",
            transferDate: "2011-10-12T05:30:00.000+0530",
            fromAccountNumber: "22539552026",
            currencyCode: "INR",
            amount: 2000,
            transactionType : "15`Transfer Between Own Accounts"
        };

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        expect(transaction.get('typeDesc')).toEqual("Transfer Between Own Accounts");

    });

    it('typeDesc with empty', function() {
        var t_transaction = {
            key : "2011-10-12",
            transferDate: "2011-10-12T05:30:00.000+0530",
            fromAccountNumber: "22539552026",
            currencyCode: "INR",
            amount: 2000
        };

        var transaction =  App.PaymentTransaction.create(t_transaction, {_account:App.HaveAccount.create()});

        spyOn(BreezeUtils, 'getPaymentTypeDescription').andReturn("Unknown");
        expect(transaction.get('typeDesc')).toEqual("");

    });
});
